<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="UTF-8">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/main.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/carousel.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        table tbody tr:nth-child(odd) {
            background: #F4F4F4;
        }

        table tbody td:nth-child(even) {
            color: #C00;
        }

        #logoimg {
            width: 150px;
            position: absolute;
            left: 15px;
            padding: 5px 5px;
        }

        #logodiv {
            position: absolute;
            left: 165px;
        }
    </style>
</head>

<body>
<div class="navbar-wrapper ">
    <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
              动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
    <jsp:include page="admin-header.jsp"></jsp:include>
</div>
<div class="container-fluid">
    <div class="row">
        <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
              动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
        <jsp:include page="admin-left.jsp"></jsp:include>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body"><br>
                    <hr style="clear:both;">
                    <div class="messages-list">
                        <c:forEach var="tbEssay" items="${tbEssayPageInfo.list}">
                            <div class="row  one-list-message ">
                                <div class="col-md-10">
                                    <p>
                                        <b><span data-toggle="tooltip"
                                                 style="color: #2a6496; font-family: 微软雅黑;font-weight: bolder;font-size: large"
                                                 title="标题">${tbEssay.essayId}、${tbEssay.essayTitle}</span></b>
                                    </p>
                                    <p><label>作者：</label>${tbEssay.essayAuthor}</p>
                                    <p><label>简介：</label>${tbEssay.essayBrief}</p>
                                    <p><label>正文：</label>${tbEssay.essayContent}</p>
                                    <p><label>来源：</label>${tbEssay.essaySource}</p>
                                    <p><label>图1：</label><img style="width: 400px;height: 240px;"
                                                              src="/upload/${tbEssay.essayImg}" class="img-rounded"
                                                              alt="无上传图片"></p>
                                    <p><label>图2：</label><img style="width: 400px;height: 240px;"
                                                              src="/upload/${tbEssay.essayImg2}" class="img-rounded"
                                                              alt="无上传图片">
                                    </p>
                                    <p><label>图3：</label><img style="width: 400px;height: 240px;"
                                                              src="/upload/${tbEssay.essayImg3}" class="img-rounded"
                                                              alt="无上传图片">
                                    </p>
                                    <p><label>不发布原因：</label><span
                                        style="color: #d43f3a; font-family: 华光综艺_CNKI;font-weight: bolder;font-size: large">${tbEssay.noReason}</span>
                                    </p>
                                    <p><label>申请日期：</label><fmt:formatDate value="${tbEssay.addTime}"
                                                                           pattern="yyyy-MM-dd HH:mm:ss "/></p>
                                    <p><label>文章类型：</label>【<span
                                        style="color: #8f001e; font-family: 华文彩云;font-weight: bolder;font-size: large">
                                        <c:if test="${tbEssay.essayType ==1}">
                                            电脑入门类
                                        </c:if>
                                        <c:if test="${tbEssay.essayType ==2}">
                                            常见故障类
                                        </c:if>
                                        <c:if test="${tbEssay.essayType ==3}">
                                            IT资讯类
                                        </c:if>
                                </span>】</p>
                                </div>
                                <div class="col-md-2">
                                    <div class='mbp'>
                                        <c:if test="${tbEssay.hasAllow ==true}">
                                            <button type="button" class="btn btn-success btn-xs"
                                                    data-toggle="tooltip"
                                                    title="允许发布" onclick="shenheOk(${tbEssay.essayId},this)">
                                                <i class=" glyphicon glyphicon-check"></i></button>
                                        </c:if>
                                        <c:if test="${tbEssay.hasAllow ==false}">
                                            <button type="button" class="btn btn-warning btn-xs"
                                                    data-toggle="tooltip"
                                                    title="拒绝发布" onclick="shenheNo(${tbEssay.essayId},this)">
                                                <i class=" glyphicon  glyphicon-off"></i></button>
                                        </c:if>
                                        <c:if test="${tbEssay.isDeleted ==false}">
                                            <button type="button" class="btn btn-danger btn-xs"
                                                    data-toggle="tooltip"
                                                    title="删除" onclick="deleteOk(${tbEssay.essayId})">
                                                <i class=" glyphicon glyphicon-remove"></i>
                                            </button>
                                        </c:if>
                                    </div>
                                </div>
                            </div>

                        </c:forEach>
                    </div>
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <tfoot>
                            <tr>
                                <td colspan="7" align="center">
                                    当前${tbEssayPageInfo.pageNum }页,总${tbEssayPageInfo.pages }页,总${tbEssayPageInfo.total }条记录
                                </td>
                            </tr>
                            <tr>
                                <td colspan="7" align="center">
                                    <ul class="pagination">
                                        <li>
                                            <c:if test="${essayType == null}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?page=1">首页</a>
                                            </c:if>
                                            <c:if test="${essayType == 1}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=1&page=1">首页</a>
                                            </c:if>
                                            <c:if test="${essayType == 2}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=2&page=1">首页</a>
                                            </c:if>
                                            <c:if test="${essayType == 3}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=3&page=1">首页</a>
                                            </c:if>
                                        </li>
                                        <!-- 判断是否有上一页，以便显示点击按钮 -->
                                        <c:if test="${tbEssayPageInfo.hasPreviousPage }">
                                            <li>
                                                <c:if test="${essayType == null}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?page=${tbEssayPageInfo.pageNum-1 }"
                                                       aria-label="Previous">
                                                        <span aria-hidden="true">&laquo;</span>
                                                    </a>
                                                </c:if>
                                                <c:if test="${essayType == 1}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=1&page=${tbEssayPageInfo.pageNum-1}"
                                                       aria-label="Previous">
                                                        <span aria-hidden="true">&laquo;</span>
                                                    </a>
                                                </c:if>
                                                <c:if test="${essayType == 2}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=2&page=${tbEssayPageInfo.pageNum-1}"
                                                       aria-label="Previous">
                                                        <span aria-hidden="true">&laquo;</span>
                                                    </a>
                                                </c:if>
                                                <c:if test="${essayType == 3}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=3&page=${tbEssayPageInfo.pageNum-1}"
                                                       aria-label="Previous">
                                                        <span aria-hidden="true">&laquo;</span>
                                                    </a>
                                                </c:if>
                                            </li>
                                        </c:if>
                                        <!-- 遍历页码 -->
                                        <c:forEach items="${tbEssayPageInfo.navigatepageNums }" var="page_Num">
                                            <c:if test="${page_Num == tbEssayPageInfo.pageNum }">
                                                <li class="active"><a href="#">${page_Num }</a></li>
                                            </c:if>
                                            <c:if test="${page_Num != tbEssayPageInfo.pageNum }">
                                                <li>
                                                    <c:if test="${essayType == null}">
                                                        <a
                                                            href="${pageContext.request.contextPath}/tbEssay/searchEssays?page=${page_Num }">${page_Num }</a>
                                                    </c:if>
                                                    <c:if test="${essayType == 1}">
                                                        <a
                                                            href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=1&page=${page_Num }">${page_Num }</a>
                                                    </c:if>
                                                    <c:if test="${essayType == 2}">
                                                        <a
                                                            href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=2&page=${page_Num }">${page_Num }</a>
                                                    </c:if>
                                                    <c:if test="${essayType == 3}">
                                                        <a
                                                            href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=3&page=${page_Num }">${page_Num }</a>
                                                    </c:if>
                                                </li>
                                            </c:if>
                                        </c:forEach>
                                        <!-- 判断是否有下一页 -->
                                        <c:if test="${tbEssayPageInfo.hasNextPage }">
                                            <li>
                                                <c:if test="${essayType == null}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?page=${tbEssayPageInfo.pageNum+1 }"
                                                       aria-label="Next">
                                                        <span aria-hidden="true">&raquo;</span>
                                                    </a>
                                                </c:if>
                                                <c:if test="${essayType == 1}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=1&page=${tbEssayPageInfo.pageNum+1 }"
                                                       aria-label="Next">
                                                        <span aria-hidden="true">&raquo;</span>
                                                    </a>
                                                </c:if>
                                                <c:if test="${essayType == 2}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=2&page=${tbEssayPageInfo.pageNum+1 }"
                                                       aria-label="Next">
                                                        <span aria-hidden="true">&raquo;</span>
                                                    </a>
                                                </c:if>
                                                <c:if test="${essayType == 3}">
                                                    <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=3&page=${tbEssayPageInfo.pageNum+1 }"
                                                       aria-label="Next">
                                                        <span aria-hidden="true">&raquo;</span>
                                                    </a>
                                                </c:if>
                                            </li>
                                        </c:if>

                                        <li>
                                            <c:if test="${essayType == null}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?page=${tbEssayPageInfo.pages }">末页</a>
                                            </c:if>
                                            <c:if test="${essayType == 1}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=1&page=${tbEssayPageInfo.pages }">末页</a>
                                            </c:if>
                                            <c:if test="${essayType == 2}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=2&page=${tbEssayPageInfo.pages }">末页</a>
                                            </c:if>
                                            <c:if test="${essayType == 3}">
                                                <a href="${pageContext.request.contextPath}/tbEssay/searchEssays?essayType=3&page=${tbEssayPageInfo.pages }">末页</a>
                                            </c:if>
                                        </li>
                                    </ul>

                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${pageContext.request.contextPath}/resources/jquery/jquery-2.1.1.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/script/docs.min.js"></script>
<script type="text/javascript">
    $(function () {

        $("[data-toggle='tooltip']").tooltip();

        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
    });

    /*审核户操作*/
    function shenheOk(essayId, obj) {
        //alert("id====" + qingjiaId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbEssay/updateStatus',

                data: {
                    essayId: essayId,
                    hasAllow: 0, //表示允许展示
                    noReason: '以允许发布·'
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        //location.replace('/tbUser/searchUser')
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    };

    /*拒绝通过操作*/
    function shenheNo(essayId, obj) {
        //alert("id====" + qingjiaId)
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbEssay/updateStatus',

                data: {
                    essayId: essayId,
                    hasAllow: 1,  //1表示拒绝展示
                    noReason: '内容涉嫌版权，请修改。'
                },
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        //location.replace('/tbUser/searchUser')
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    }

    //删除操作

    function deleteOk(essayId) {
        if (confirm("确定删除?")) {
            location.replace("/tbEssay/deleteOk?essayId=" + essayId)
        }
    }
</script>
</body>
</html>
